#pragma once


#include "define.h"
#include <cstdint>
#include <unistd.h>
#include <string>
#include <memory>
#include <vector>
#include <thread>
#include <mutex>
#include <map>

class Channel;
class TaskTimer;

class LoopEvent {

public:
    LoopEvent();
    ~LoopEvent();
    void Run();
    void DoTask();
    void PushTask(TaskCallback && task);
    void PushAfterTask(int64_t after_tm_ms, TaskCallback && func);
    void StopLoopEvent(bool status);
public:
    int64_t AddEventType(std::shared_ptr<Channel> channel, int event_type);
    void Update(int64_t channel_id, int event_type);
    void Remove(int64_t channel_id, int event_type);
private:
    int m_epoll_fd;
    std::mutex m_mtx;
    std::vector<TaskCallback> m_task_vec;
    std::map<int64_t, std::shared_ptr<Channel>> m_channel_map;
    int64_t m_channel_id_count;

    bool m_loop_status;
private:
    std::shared_ptr<TaskTimer> m_task_timer;
};